package com.qf.six.ssm.controller.order;

import com.qf.six.ssm.commen.request.RequestParams;
import com.qf.six.ssm.commen.vo.OrderVo;
import com.qf.six.ssm.commen.vo.ResponseResult;
import com.qf.six.ssm.entity.Order;
import com.qf.six.ssm.service.order.OrderService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/form")
public class OrderController {
    @Resource
    OrderService orderService;

    /**
     * 订单初始化展示所有订单
     * @param params
     * @return
     */
    @PostMapping("/info")
    public ResponseResult<List<OrderVo>> info(@RequestBody RequestParams params) {
        List<OrderVo> list = orderService.info(params);
        return ResponseResult.success(list);
    }

    /**
     * 根据订单交易状态展示订单
     * @param params
     * @param tid
     * @return
     */
    @GetMapping("/info/{id}")
    public ResponseResult<List<OrderVo>> selectOrderByTid(RequestParams params,@PathVariable("id") Integer tid) {
        List<OrderVo> list =  orderService.selectOrderByTid(params, tid);
        return ResponseResult.success(list);
    }

    /**
     * 展示该用户下状态为1的订单
     * @param uid
     * @return
     */
    @GetMapping("/select/{id}")
    public ResponseResult<List<OrderVo>> selectOrderByUid(@PathVariable("id") Integer uid) {
        List<OrderVo> list = orderService.selectOrderByUid(uid);
        return ResponseResult.success(list);
    }

    /**
     * 假删除
     * @param order
     * @return
     */
    @PutMapping("/delete")
    public ResponseResult<Integer> fakeDelete(@RequestBody Order order) {
        return ResponseResult.success(orderService.fakeDelete(order));
    }


    /**
     * 生成订单
     * @param order
     * @return
     */
    @PostMapping("/add")
    public ResponseResult<Integer> insertOrder(Order order){
        int result = orderService.insertOrder(order);
        return ResponseResult.success(result);
    }

    /**
     * 真删除订单
     * @param oid
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public ResponseResult<Integer> deleteOrder(@PathVariable("id") Integer oid) {
        int result = orderService.deleteOrder(oid);
        return ResponseResult.success(result);
    }

    /**
     * 更新订单状态
     * @param order
     * @return
     */
    @PutMapping("/put")
    public ResponseResult<Integer> putOrder(@RequestBody Order order) {
        int result = orderService.putOrder(order);
        return ResponseResult.success(result);
    }


}
